package cn.rengy.web.framework.wxmp.component.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import cn.rengy.tpa.wxmp.component.auth.ComponentAuthManager;

import cn.rengy.web.framework.wxmp.component.token.ComponentTokenService;

@Service
public class ComponentAuthService {
	//private static Logger logger = LoggerFactory.getLogger(ComponentAuthService.class);
	@Autowired(required=false)
	private ComponentTokenService componentTokenService;


	@Value("${default_component_appid:null}")
	private String default_component_appid;

	@Value("${domain:null}")
	private String domain;
	/**
	 * 移动端访问授权
	 * @return
	 * @throws Exception 
	 */
	public String getWxAuthURL() throws Exception{
		String pre_auth_code=componentTokenService.preAuthCode(default_component_appid);
		String redirectURL=domain+"/wxtp/authSuccess/"+default_component_appid;
		String url=ComponentAuthManager.generateWxAuthURI(default_component_appid, pre_auth_code, redirectURL, 3);
		return url;
	}
	/**
	 * PC端授权扫码授权
	 * @return
	 * @throws Exception
	 */
	public String getPcAuthURL() throws Exception{
		String pre_auth_code=componentTokenService.preAuthCode(default_component_appid);
		String redirectURL=domain+"/wxtp/authSuccess/"+default_component_appid;
		String url=ComponentAuthManager.generatePcAuthURI(default_component_appid, pre_auth_code, redirectURL, 3);
		return url;
	}
}
